import fs from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'

// fs.readFile('../corpus/data.json', 'utf-8', (err, data) => {
//     if (err) {
//         console.log(err)
//     } else {
//         console.log(data)
//     }
// })

// 相对路径
// const data = fs.readFileSync('../corpus/data.json', 'utf-8')
// console.log(data)

// 绝对路径
// 获取当前文件的绝对路径
const url = import.meta.url
const path = resolve(dirname(fileURLToPath(url)), '../corpus/data.json')
let data = fs.readFileSync(path, 'utf-8')
data = JSON.parse(data)
// console.log(data);

import { randomInt } from './random.js'

// 随机生成一个标题
const title = data.title[randomInt(0, data.title.length)]
console.log(title);

// 随机生成一个内容
const famous = data.famous[randomInt(0, data.famous.length)]
console.log(famous);

// 随机生成一个段落
const bosh = data.bosh[randomInt(0, data.bosh.length)]
console.log(bosh);





